﻿@model IEnumerable<MasResourceType>

@{
    ViewBag.Title = "จำแนกประเภทพัสดุ";
    ViewBag.Descr = "ประเภทพัสดุที่ใช้สำหรับการซื้อจ้างและบริหารในองค์กร";
}
<style> 
    </style>

@using (Html.BeginForm("DeleteAll", "MasResourceType", FormMethod.Post, new {@id="form"}))
{
    @Html.AntiForgeryToken()
    <div class="row-fluid">
        <div class="block-button-menu-above">
           @* @if(GimsMembership.IsCurrentUserAdmin)
            {
                @Html.ButtonAdd()
                @Html.ButtonDeleteAll()
            }*@
        </div>
        @Html.ValidationSummary(true, "", new
            {
                @class = "alert alert-error"
            })
        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">@ViewBag.Title</div>
                @Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width: 50px;">
                        <!-- Check box delete multiple records column-->
                        <label>
                            <input type="checkbox" disabled="disabled"/>
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th class="center" style="width:60px">
                        @Html.DisplayNameFor(model => model.Code)
                    </th >
                    <th class="center" style="width:100px">
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th class="center" >
                        @Html.DisplayNameFor(model => model.Descr)
                    </th>
                    <th class="center" style="width:100px">
                        @Html.DisplayNameFor(model => model.DepreciationCalculate)
                    </th>
                    <th class="center" style="width:100px">
                        จำนวนหมวด
                    </th>
                    <th class="center" style="width: 80px;">
                        <!-- Empty head column for export buttons -->&nbsp;
                    </th>
                </tr>
            </thead>

            <tbody>
                @foreach (var m in Model)
                {
                    <tr>                                                         
                        <td class="center">
                            <!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.ResTypeId)" disabled="disabled" />
                                <span class="lbl"></span>
                            </label>
                        </td>
                        <td class="center">
                            @m.Code
                            @*@Html.ActionLink(@m.Code + " ", "Details", new{Id = m.ResTypeId})*@
                        </td>
                        <td>
                            @m.Name
                            @*@Html.ActionLink(@m.Name + " ", "Details", new{Id = m.ResTypeId})*@
                        </td>
                        <td>
                            @Html.Raw(m.Descr.UseHtmlNewLineTag())
                        </td>
                        <td class="center">
                            @Html.Raw(m.DepreciationCalculate == "Y" ? "<span class='green' style='font-weight:bold'>ใช่</span>" : "<span class='red bold' style='font-weight:bold'>ไม่ใช่</span>")
                        </td>
                        <td class="center">
                            @m.AmountOfGroup
                        </td>
                        <td class="td-actions">
                            <div class="hidden-phone visible-desktop btn-group ">
                                <!-- Buttons On PC /-->
                                <a class="btn btn-mini btn-info" data-rel="tooltip" href="@Url.Action("Index", "MasResourceGroup", new {@m.ResTypeId})" role="button" data-original-title="" title=""><i class="icon-folder-open bigger-120"></i> หมวดพัสดุ</a>
                                @*<a class="btn btn-mini btn-grey" data-rel="tooltip" href="@Url.Action("Details", new {id=@m.ResTypeId})" role="button" data-original-title="" title=""><i class="icon-search bigger-120"></i></a>*@
                                @* @if(GimsMembership.IsCurrentUserAdmin)
                                { 
                                <a class="btn btn-mini btn-success" data-rel="tooltip" href="@Url.Action("Edit", new {id=@m.ResTypeId})" role="button" data-original-title="" title=""><i class="icon-edit bigger-120"></i></a>
                                
                                <a class="btn btn-mini btn-danger" data-rel="tooltip" onclick="bootbox.confirm('ท่านต้องการยืนยันการลบข้อมูลนี้หรือไม่ ?', function(result) { if (result) window.location.href='@Url.Action("Delete", new {id=@m.ResTypeId})'; });" role="button" data-original-title="" title=""><i class="icon-trash bigger-120"></i></a>
                                 } *@
                            </div>
                            
                            <div class="hidden-desktop visible-phone">
	                            <!-- Buttons/Tooltip On Tablet (or small monitor) /-->
	                            <div class="inline position-relative">
		                            <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
			                            <i class="icon-caret-down icon-only bigger-120"></i>
		                            </button>
		                            <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                        <li>
                                            <a class="btn btn-mini btn-info" data-rel="tooltip" href="@Url.Action("Index", "MasResourceGroup", new {@m.ResTypeId})" role="button" data-original-title="" title=""><i class="icon-folder-open bigger-120"></i> หมวดพัสดุ</a>
                                        </li>
                                        @*<li>
                                            <a class="btn btn-mini btn-grey" data-rel="tooltip" href="@Url.Action("Details", new {id=@m.ResTypeId})" role="button" data-original-title="" title=""><i class="icon-search bigger-120"></i></a>
                                        </li>*@
		                            </ul>
	                            </div>
                            </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
    <script type="text/javascript">
        var o = $('#table').dataTable({
            "aoColumns": [
                { "bSortable": false },
                null,
                null,
                null,
                null,
                null,
                { "bSortable": false }
            ]
        });
        

        $(function() 
        {

            $('table th input:checkbox').on('click', function() {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function() {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });

            });

            $('[data-rel=tooltip]').tooltip();

            $("#form").submit(function(e) {
                e.preventDefault();
                var currentForm = this;
                bootbox.confirm("คุณแน่ใจหรือไม่", function(c) {
                    if (c) {
                        $.ajax({
                            url: "@Url.Action("DeleteAll")",
                            type: "post",
                            dataType: "json",
                            data: $(currentForm).serialize(),
                            context: document.body,
                            success: function(s) {
                                if (s.success) {
                                    location.reload();
                                }
                            },
                            error: function(xhr, status, error) {
                                alert("Status: " + status + ", Error: " + error + ", XHR: " + xhr.readyState);
                            },
                            statusCode: {
                                404: function() {
                                    alert("Page not found");
                                }
                            }
                        });
                    }
                });
                return false;
            });
        });

    </script>
}

@*

@model IEnumerable<MasResourceType>

@{
    ViewBag.Title = "จำแนกประเภทพัสดุ";
    ViewBag.Descr = "ข้อมูลประเภทพัสดุ ที่ใช้สำหรับการซื้อจ้างและบริหารในองค์กร";
}

<div class="widget-box span4">
	<div class="widget-header header-color-orange">
		<h4 class="lighter smaller"><i class="icon-sitemap"></i>&nbsp;&nbsp;แผนผัง จำแนกประเภทพัสดุ</h4>
	</div>

	<div class="widget-body">
        <div class="widget-main padding-8">
            
            xxx
             @Html.TreeView("tree", Model, l => l.Children, l => l.Name, false, true) 
            <div id="tree1" class="tree tree-selectable">
                 
            </div>
        </div>
    </div>
</div>

<div class="span8">
    @foreach(var m in Model)
    {
        @m.Name <br/>
    }
</div>
@*<div class="span8">
@using (Html.BeginForm("DeleteAll", "MasResource", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    
    <div class="row-fluid">    
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>

        @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })

        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
                    <h4 class="lighter smaller">@ViewBag.Title</h4>
                </div>
                <div class="btn-group pull-right">
                    <button data-toggle="dropdown" class="btn btn-small btn-primary dropdown-toggle">
				        Export
				        <i class="icon-angle-down icon-on-right"></i>
			        </button>

			        <ul class="dropdown-menu dropdown-danger" style="min-width:80px;">
				        <li>
					        <a href="#"><i class="icon-file bigger-125"></i>  Word</a>
				        </li>

				        <li>
					        <a href="#"><i class="icon-table bigger-125"></i>  Excel</a>
				        </li>

				        <li>
					        <a href="#"><i class="icon-file-alt bigger-125"></i>  PDF</a>
				        </li>
			        </ul>
                </div>
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
                        <label>
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Descr)
                    </th>

                    <th class="center" style="width:80px;">

                    </th>
                </tr>
            </thead>

            <tbody>
                @foreach(var m in Model)
                {
                    <tr>
                        <td class="center">
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.ResTypeId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>

                        <td>@Html.ActionLink(@m.Name, "Details", new { Id=m.ResTypeId })</td>
                        <td>@Html.DisplayFor(modelItem => m.Descr)</td>
                
                        <td class="td-actions">
                            <div class="hidden-phone visible-desktop btn-group">
                                @Html.ButtonDetails(new { Id=m.ResTypeId }, true)
                                
                                @Html.ButtonEdit(new { Id=m.ResTypeId }, true)

                                @Html.ButtonDelete(new { Id=m.ResTypeId }, true)
                            </div>

                            <div class="hidden-desktop visible-phone">
                                <div class="inline position-relative">
                                    <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                        <i class="icon-caret-down icon-only bigger-120"></i>
                                    </button>

                                    <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                        <li>
                                            <a href="/MasPurchaseRegular/Details/@(m.ResTypeId)" class="tooltip-gray" data-rel="tooltip" title="ดูรายละเอียด" data-placement="left">
                                                <span class="gray">
                                                    <i class="icon-search"></i>
                                                </span>
                                            </a>
                                        </li>

                                        <li>
                                            <a href="/MasPurchaseRegular/Edit/@(m.ResTypeId)" class="tooltip-success" data-rel="tooltip" title="แก้ไข" data-placement="left">
                                                <span class="green">
                                                    <i class="icon-edit"></i>
                                                </span>
                                            </a>
                                        </li>

                                        <li>
                                            <a href="/MasPurchaseRegular/Delete/@(m.ResTypeId)" class="tooltip-error" data-rel="tooltip" title="ลบ" data-placement="left">
                                                <span class="red">
                                                    <i class="icon-trash"></i>
                                                </span>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}
</div>

@section scripts {
    
	<script type="text/javascript">
		$(function () {
		    var oTable1 = $('#table').dataTable({
		        "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    { "bSortable": false }
		        ]
		    });

		    $('table th input:checkbox').on('click', function () {
		        var that = this;
		        $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});

		    });

		    $('[data-rel=tooltip]').tooltip();

		    $("form").submit(function () {
		        var currentForm = this;
		        bootbox.confirm(function (result) {
		            var _result = result;
		            if (result) {
		                $.ajax({
		                    url: "DeleteAll",
		                    type: "post",
		                    dataType: "json",
		                    data: $(currentForm).serialize(),
		                    success: function (result) {
		                        if (result.success) {
		                            location.reload();
		                        }
		                        else {
		                        }
		                    }
		                });
		            }
		        })
		        return false;
		    });

		    var tree_data = {
		        '1': { name: 'AAAAA', type: 'item', id: '1' },
		        '2': { name: 'BBBBB', type: 'item', id: '2' },
		        '3': { name: 'CCCCC', type: 'item', id: '3' },
		        '4': { name: 'DDDDD', type: 'item', id: '4' }
		    }
		    tree_data['1']['additionalParameters'] = {
		        'children': {
		            '5': { name: 'AAAAA-AAAAA', type: 'item', id: '5' },
		            '6': { name: 'AAAAA-BBBBB', type: 'item', id: '6' }
		        }
		    };

		    var treeDataSource = new DataSourceTree({ data: tree_data });

		    $('#tree1').ace_tree({
		        dataSource: treeDataSource,
		        multiSelect: false,
		        loadingHTML: '<div class="offset1"><i class="icon-refresh icon-spin blue"></i></div>',
		        'open-icon': 'icon-minus',
		        'close-icon': 'icon-plus',
		        'selectable': true,
		        'selected-icon': 'icon-ok',
		        'unselected-icon': 'icon-remove'
		    });

		    $('#tree1').on('selected', function (evt, data) {
		        alert('item selected: ' + data[0]);
		    });
		})

	</script>

}*@